package com.xyb.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5 工具类
 */
public class MD5Utils {
    /**
     * MD5 加密
     * @param str
     * @return
     */
    public static String getMD5(String str){
        byte[] bytes = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            bytes = md5.digest(str.getBytes());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return new String(bytes);
    }

    public static void main(String[] args) {
        String str = "111111";
        String md5 = getMD5(str);
        System.out.println("md5加密过后的密文: " + md5);

        String md51 = getMD5(str);
        System.out.println("第二次加密过后的密文: " + md51);

        System.out.println("两次加密是否相同: " + md51.equals(md5));
    }
}
